import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const List = []
const count = 30

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id:'@increment(1, 100)',
    withdrawNo: '@float(0, 100, 2, 2)',
    shopNo: '@int(1000, 10000, 2, 2)',
    account: '@float(0, 100, 2, 2)',
    name: Mock.Random.ctitle(6),
    money: '@int(0, 100, 2, 2)',
    fee: '@int(0, 100, 2, 2)',
    moneyCheck: '@float(0, 100, 2, 2)',
    requestUrl:'@first',
    receiveUrl:'@first',
    type:'',
    bank:'@first',
    deposit:'@first',
    memberDeposit:'@first',
    memberCardNo:'@first',
    memberName: '@first',
    paymentType: '@first',
    operator:'@first',
    comment:'',
    withdrawTime:  +Mock.Random.date('T'),
    operateTime:  +Mock.Random.date('T'),
    riskTime:  +Mock.Random.date('T'),
    updateTime:  +Mock.Random.date('T'),
    min:'@int(0, 100, 2, 2)',
    max:'@int(100, 10000, 2, 2)',
    // register_ip: Mock.Random.ip(),
    // login_ip: Mock.Random.ip(),
    // name: '@first',
    // nickname: '@first',
    // comment: '',
    // proxy: '@float(0, 100, 2, 2)',
    // level: '@integer(1, 3)',
    // balance: '@float(60, 100, 1)',
    // money_stream:'@float(60, 100, 1)',
    'effectPlatform|1': _.map(consts.PAYMENT_PLATFORM, 'value'),
    'type|1': [1,2], // 1是银行，2是三方
    'escrowPlatform|1': _.map(consts.ESCROWS_PLATFORM, 'value'),
    'platform|1': _.map(consts.PAYMENT_PLATFORM, 'value'),
    'withdrawStatus|1': _.map(consts.WITHDRAW_STATUS, 'value'),
    'riskType|1': _.map(consts.RISK_TYPES, 'value'),
    'withdrawExceptionStatus|1': _.map(consts.WITHDRAW_EXCEPTION_STATUS, 'value'),
    'accountType|1': _.map(consts.ACCOUNT_TYPE, 'value'),
    'memberBankName|1': _.map(consts.PAYEE_BANKS, 'value'),
    'status|1': _.map(consts.WITHDRAW_STATUS, 'value'),
    'escrowStatus|1': _.map(consts.ESCROWS_STATUS, 'value'),
    'auditStatus|1': _.map(consts.REORDER_AUDIT_STATUS, 'value'),
  }))
}

export default {
  [api.WITHDRAW_LIST]: config => {
    const { page, limit } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.WITHDRAW_EXCEPTION_LIST]: config => {
    const { page, limit } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.WITHDRAW_AUDIT_LIST]: config => {
    const { page, limit } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.WITHDRAW_SHOP_LIST]: config => {
    const { page=1, limit=20 } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.WITHDRAW_DETAIL]: config => {
    const {id, page = 1, limit = 20 } = param2Obj(config.body)

    const item = _.find(List,o=>o.id == id)


    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail: item
      },
      code: 1,
    };
  },
  [api.WITHDRAW_CONFIGS]: config => {
    const configs = {
      min: 10,
      max: 1000,
      daybook: 10,
      freeTimes: 10,
      overflowFee: 50,
      scope: '2',
      maxFee: 200
    }

    return {
      data: {
        configs: configs
      },
      code: 1,
    };
  },

  [api.WITHDRAW_CONFIGS_UPDATE]: config => {
    const {configs} = param2Obj(config.body)
    return {
      data: {
        configs: configs
      },
      code: 1,
    };
  },

  [api.WITHDRAW_ESCROWS]: config =>{
    const { page =1, limit=20 } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    console.log(pageList)
    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.WITHDRAW_ESCROW_DETAIL]: config => {
    const {id, page = 1, limit = 20 } = param2Obj(config.body)

    const item = _.find(List,o=>o.id == id)


    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail: item
      },
      code: 1,
    };
  },
}
